package servlet;

import dao.PersonDAO;
import entity.PersonBean;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.sql.SQLException;
@WebServlet("/group/people/personEdit")
public class PersonEditServlet extends HttpServlet {
    public PersonEditServlet() {
        super();
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id=req.getParameter("id");
        PersonDAO dao = new PersonDAO();
        PersonBean editList;
        try {
            editList = dao.fillEditMessage(id);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        req.setAttribute("editList",editList);
        req.getRequestDispatcher("person_edit.jsp").forward(req, resp);
    }
}
